<%@page import="java.util.Locale"%>
<%@page import="java.text.NumberFormat"%>
<%@page import="com.tubeonfire.util.ApplicationHelper"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.tubeonfire.util.RecentViewHelper"%>
<%@page import="java.util.TreeMap"%>
<%@page import="com.tubeonfire.model.AdvertisingModel"%>
<%@page import="com.tubeonfire.entity.Advertising"%>
<%@page import="com.tubeonfire.search.TubeSearchModel"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="com.tubeonfire.model.TagModel"%>
<%@page import="com.tubeonfire.model.PlaylistModel"%>
<%@page import="com.tubeonfire.model.TubeModel"%>
<%@page import="com.tubeonfire.entity.Tag"%>
<%@page import="com.tubeonfire.entity.Playlist"%>
<%@page import="com.tubeonfire.entity.Tube"%>
<%@page import="java.util.List"%>	
 <div id="rightsidecontent">
 	<div id="rightsidecontent_inner">
         <aside>                 
          	<%        
          		NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
          		int place = 4;
          		int position = 999;
          		String isAdmin = request.getParameter("isAdmin");
          		Advertising ads01 = AdvertisingModel.getByPlaceAndPosition(place, position);
          		if(ads01!=null&&ads01.getId().length()>0){
          			%>
          			<div class="advWrap adv-250x250 clearafter" style="border: none;">
          				<%
          					if(ads01.getType()==1){
          						%>
          						<%=ads01.getContent() %>	
          						<%
          					}else{
          						String imgUrl = ads01.getContent();
        						imgUrl = "/image?key=" + imgUrl + "&size=250";
          						%>
          						<a title="<%=ads01.getTitle()%>" href="<%=ads01.getLink()%>">
          							<img alt="<%=ads01.getTitle() %>" src="<%=imgUrl%>">
          						</a> 
          						<%
          					}
          				%>          				
          			</div>
          			<%
          		}else if(isAdmin!=null&&isAdmin.equals("1")){
            		%>
            		<div class="advWrap adv-250x250 clearafter">
						<div>
	                    	<a href="/admin/advertising/add?place=<%=place %>&position=<%=position %>" title="Add Advertising">Add Advertising Here (250 x 250)</a>			             
	                    </div>
                    </div>
            		<%
            	}
          	%>		 
          	
          	<%
           		PlaylistModel plModel = new PlaylistModel();
           		plModel.setLimit(10);
           		plModel.setPage(1);
           		plModel.prepareList(true);           		
           		if(plModel.getListResult().size()>0){
           %>
             <div class="box-green">
                 <h3 class="title">Playlist</h3>
                 <div class="box-content">
                     <ul class="item-listing">
                     <%
                   		for(Playlist pl: plModel.getListResult()){
                   			String imgUrl = pl.getImageKey();
    						imgUrl = "/image?key=" + imgUrl + "&size=87";
                     %>
                         <li class="clearafter">
                             <div class="description">
                                 <h4><a href="/playlist/<%=pl.getId() %>/<%=pl.getAlias()%>" title="<%=pl.getTitle()%>"><%=pl.getTitle() %></a></h4>
                                 <a href="/playlist/<%=pl.getId() %>/<%=pl.getAlias()%>" title="<%=pl.getDescription()%>">
                                 	<%=pl.getDescription() %>
                               	 </a>
                             </div>
                            <a class="link-image-scale" href="/playlist/<%=pl.getId() %>/<%=pl.getAlias()%>" title="<%=pl.getTitle()%>">
                             	<span><img src="<%=imgUrl%>" alt="<%=pl.getTitle() %>" title="<%=pl.getTitle() %>" /></span>
                           	</a>
                         </li>
                      <%
                   		}
                      %>                                                                
                     </ul>
                 </div>
             </div>
             <%
           		}
             %>        
                      
           <%
           		position = 998;
          		ads01 = AdvertisingModel.getByPlaceAndPosition(place, position);
          		if(ads01!=null&&ads01.getId().length()>0){
          			%>
          			<div class="advWrap adv-250x250 clearafter" style="border: none;">
						<div>
	          				<%
	          					if(ads01.getType()==1){
	          						%>
	          						<%=ads01.getContent() %>	
	          						<%
	          					}else{
	          						String imgUrl = ads01.getContent();
	        						imgUrl = "/image?key=" + imgUrl + "&size=250";
	          						%>
	          						<a title="<%=ads01.getTitle()%>" href="<%=ads01.getLink()%>">
	          							<img alt="<%=ads01.getTitle() %>" src="<%=imgUrl%>">
	          						</a> 
	          						<%
	          					}
	          				%>          				
	          			</div>
          			</div>
          			<%
          		}else if(isAdmin!=null&&isAdmin.equals("1")){
            		%>
            		<div class="advWrap adv-250x250 clearafter">
						<div>
	                    	<a href="/admin/advertising/add?place=<%=place %>&position=<%=position %>" title="Add Advertising">Add Advertising Here (250 x 250)</a>			             
	                    </div>
                    </div>
            		<%
            	}
          	%>	
           
           <% 
         	TubeSearchModel tubeSearch = new TubeSearchModel();
         	tubeSearch.setLimit(10);
         	tubeSearch.setPage(1);
         	tubeSearch.prepareMostView();
   			if (tubeSearch.getListResult().size() > 0) {
         %>
             <div class="box-blue">
                 <h3 class="title">
                 	<% 
                 		if(ApplicationHelper.getApplicationType()==1){
                 			%>
                 			Most View
                 			<%
                 		}else{
                 			%>
                 			Recent View
                 			<%
                 		}         		
                 	%>
                 </h3>
                 <div class="box-content">
                     <ul class="item-listing">
                    <%
                    	for(Tube tub : tubeSearch.getListResult()){	                    		
							String imgUrl = tub.getImageUrl();
							if(!imgUrl.contains("http://")){								
        						imgUrl = "/image?key=" + imgUrl + "&size=87";														
							}
					%>
                         <li class="clearafter">
                             <div class="description">
                                 <h4><a href="/video/<%=tub.getId() %>/<%=tub.getAlias() %>.html" title="<%=tub.getTitle()%>"><%=tub.getTitle() %></a></h4>
                                 <%
                                 	if(ApplicationHelper.getApplicationType()==1){
                                 		%>
                                 		<span class="view-today"><%=nf.format(tub.getView()) %>&nbsp;view<%=tub.getView()>1?"s":"" %></span>		
                                 		<%
                                 	}
                                 %>                                 
                             </div>
                             <a class="link-image-scale" href="/video/<%=tub.getId() %>/<%=tub.getAlias() %>.html" title="<%=tub.getTitle()%>">
                             	<span><img src="<%=imgUrl %>" alt="<%=tub.getTitle() %>" title="<%=tub.getTitle() %>"/></span>
                          	 </a>
                         </li>
                   	 <%
						}
                     %>                                      
                     </ul>
                 </div>
             </div>
           <%
   			}
           %>
           
           
             <%
             	position = 997;
          		ads01 = AdvertisingModel.getByPlaceAndPosition(place, position);
          		if(ads01!=null&&ads01.getId().length()>0){
          			%> 
          			<div class="advWrap adv-250x250 clearafter" style="border: none;">
						<div>
	          				<%
	          					if(ads01.getType()==1){
	          						%>
	          						<%=ads01.getContent() %>	
	          						<%
	          					}else{
	          						String imgUrl = ads01.getContent();
	        						imgUrl = "/image?key=" + imgUrl + "&size=250";
	          						%>
	          						<a title="<%=ads01.getTitle()%>" href="<%=ads01.getLink()%>">
	          							<img alt="<%=ads01.getTitle() %>" src="<%=imgUrl%>">
	          						</a> 
	          						<%
	          					}
	          				%>          				
	          			</div>
          			</div>
          			<%
          		}else if(isAdmin!=null&&isAdmin.equals("1")){
            		%>
                	<div class="advWrap adv-250x250 clearafter">
						<div>
                    		<a href="/admin/advertising/add?place=<%=place %>&position=<%=position %>" title="Add Advertising">Add Advertising Here (250 x 250)</a>			             
                    	</div>
                    </div>
            		<%
            	}
         	%>	
             <%
             	TagModel tagModel = new TagModel();             	
             	if(tagModel.getTagPool().size()>0){
             %>
             <div class="tags">
             	<h3 class="title">Tag</h3>
                 <ul>
                 	<%
                 		for(String tag: tagModel.getTagPool()){
                 	%>
                 	<li><a href="/keyword/<%=tag%>" title="<%=tag%>"><%=tag %></a></li>
       				<%
                 		}
       				%>
                 </ul>
             </div>
             <%
             	}
             %>   
             <%
             	position = 996;
          		ads01 = AdvertisingModel.getByPlaceAndPosition(place, position);
          		if(ads01!=null&&ads01.getId().length()>0){
          			%>
          			<div class="advWrap adv-250x250 clearafter" style="border: none;">
						<div>
	          				<%
	          					if(ads01.getType()==1){
	          						%>
	          						<%=ads01.getContent() %>	
	          						<%
	          					}else{
	          						String imgUrl = ads01.getContent();
	        						imgUrl = "/image?key=" + imgUrl + "&size=250";
	          						%>
	          						<a title="<%=ads01.getTitle()%>" href="<%=ads01.getLink()%>">
	          							<img alt="<%=ads01.getTitle() %>" src="<%=imgUrl%>">
	          						</a> 
	          						<%
	          					}
	          				%>          				
	          			</div>
          			</div>
          			<%
          		}else if(isAdmin!=null&&isAdmin.equals("1")){
            		%>
            		<div class="advWrap adv-250x250 clearafter">
						<div>
	                    	<a href="/admin/advertising/add?place=<%=place %>&position=<%=position %>" title="Add Advertising">Add Advertising Here (250 x 250)</a>			             
	                    </div>
                    </div>
            		<%
            	}
         	%>
         </aside>
     </div>
 </div>